package com.yunhe.java.pro13map;

import java.util.*;

/**
 * Created by Administrator on 2017/8/7 0007.
 */
public class JiheMap {
    public static void main(String[] args){
        Map map=new HashMap<>();
        map.put("001","张三");
        map.put(001,"王五");
        map.put(002,"严秀");
        map.put(003,"王五");
        map.put("002","李四");
        map.remove(001);//删除
        map.put("002","王麻子");//替换
        System.out.println(map.get("002"));
        System.out.println(map.containsKey(002));
        int size=map.size();
        System.out.println(size);

        //先遍历key然后通过key来获取value值
        System.out.println("遍历方式1：");
        Set set=map.keySet();//获取map中的key为set集合
        Iterator iterator=set.iterator();
        while(iterator.hasNext()){
            Object key=iterator.next();
            Object value=map.get(key);
            System.out.println(key+":"+value);
        }
        System.out.println("遍历方式2：");
        Set entrys=map.entrySet();
        Iterator iterator1=entrys.iterator();
        while(iterator1.hasNext()){
            Map.Entry entry=(Map.Entry) iterator1.next();
            System.out.print(entry.getKey()+":"+entry.getValue()+"  ");
        }
        Collection values=map.values();
        System.out.print(values);
    }
}
